export default {
  local (key, value) {
    if (arguments.length === 2) {
      return localStorage.setItem(key, JSON.stringify(value))
    } else {
      return localStorage.getItem(key) && localStorage.getItem(key) !== 'undefined' ? JSON.parse(localStorage.getItem(key)) : ''
    }
  },
  session (key, value) {
    if (arguments.length === 2) {
      return sessionStorage.setItem(key, JSON.stringify(value))
    } else {
      return sessionStorage.getItem(key) && sessionStorage.getItem(key) !== 'undefined' ? JSON.parse(sessionStorage.getItem(key)) : ''
    }
  },
  isWxBrowser () {
    let ua = window.navigator.userAgent.toLowerCase()
    // 通过正则表达式匹配ua中是否含有MicroMessenger字符串
    let _micro = ua.match(/MicroMessenger/i)
    if (_micro === 'micromessenger' || (_micro && _micro[0] === 'micromessenger')) {
      return true
    } else {
      return false
    }
  }
}
